# list1=input().split()
# n=int(input())
# left=0
# right=left+n
# count=0
#
# while right <= n:
#     lsit=set(list1[left:right])
#     list2=list(lsit)
#     count=max(count,len(list2))
#     left+=1
#     right+=1
# print(count)

# 输入获取
arr = input().split()
n = int(input())


# 算法入口
def getResult(arr, n):
    count = {
        "0": 0,
        "1": 0,
        "2": 0
    }

    l = 0
    r = l + n

    for c in arr[l:r]:
        count[c] += 1

    maxV = max(count.values())

    while r < len(arr):
        add = arr[r]
        remove = arr[l]

        r += 1
        l += 1

        count[add] += 1
        count[remove] -= 1

        maxV = max(maxV, count[add])

    return maxV


# 算法调用
print(getResult(arr, n))